home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / DIALOG.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  309 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Definition of TDialog class and TDialogAttr struct
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_DIALOG_H)
  10. #define OWL_DIALOG_H
  11.  
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. //
  25. // struct TDialogAttr
  26. // ~~~~~~ ~~~~~~~~~~~
  27. // TDialog creation attributes
  28. //
  29. struct TDialogAttr {
  30.   char far* Name;
  31.   uint32    Param;
  32. };
  33.  
  34.  
  35. //
  36. // class TControlEnabler
  37. // ~~~~~ ~~~~~~~~~~~~~~~
  38. // A TCommandEnabler for child controls in a dialog
  39. //
  40. class _OWLCLASS TControlEnabler : public TCommandEnabler {
  41.   public:
  42.     TControlEnabler(uint id, HWND hWndReceiver = 0);
  43.  
  44.     // Override virtuals
  45.     //
  46.     void Enable(bool enable = true);
  47.     void SetText(const char far* text);
  48.  
  49.     // Use this method with only buttons!
  50.     //
  51.     void SetCheck(int check);
  52. };
  53.  
  54.  
  55. //
  56. // class TDialog
  57. // ~~~~~ ~~~~~~~
  58. class _OWLCLASS TDialog : virtual public TWindow {
  59.   public:
  60.     TDialog(TWindow* parent, TResId resId, TModule* module = 0);
  61.  
  62.    ~TDialog();
  63.  
  64.     // Override this to process messages within the dialog function
  65.     // Return true if message handled, false if not.
  66.     //
  67.     virtual bool    DialogFunction(uint message, TParam1 wParam, TParam2 lParam);
  68.  
  69.     // Virtual handler for WM_INITDIALOG message, called from DialogFunction()
  70.     //
  71.     virtual bool    EvInitDialog(HWND hWndFocus);
  72.  
  73.     // Initialize dialog controls with contents of RT_DLGINIT
  74.     //
  75.     bool            PerformDlgInit();
  76.  
  77.     // Handler for WM_SETFONT, is dispatched from DialogFunction() once
  78.     // during dialog creation, subsequently as normal.
  79.     //
  80.     void            EvSetFont(HFONT hFont, bool redraw);
  81.  
  82.     // Create a modeless dialog box, and perform actual create call
  83.     //
  84.     virtual bool    Create();
  85.     virtual HWND    DoCreate();
  86.  
  87.     // Create a modal dialog box, and perform actual modal execute call
  88.     //
  89.     virtual int     Execute();
  90.     virtual int     DoExecute();
  91.  
  92.     // Override virtual functions defined by class TWindow
  93.     //
  94.     bool            PreProcessMsg(MSG& msg);
  95.     void            CloseWindow(int retValue = IDCANCEL);
  96.     void            Destroy(int retValue = IDCANCEL);
  97.  
  98.     void            SetCaption(const char far* title);
  99.  
  100.     TDialogAttr&    GetDialogAttr();
  101.     void            SetDialogAttr(TDialogAttr attr);
  102.  
  103.     bool            GetIsModal() const;
  104.     void            SetIsModal(bool ismodal);
  105.  
  106.     // Handy dialog functions
  107.     //
  108.     uint            GetDefaultId() const;
  109.     void            SetDefaultId(uint id);
  110.     void            MapDialogRect(TRect& rect);
  111. #if defined(BI_PLAT_WIN32)
  112.     void            Reposition();
  113. #endif
  114.  
  115.     // Enumeration to be used when invoking the 'SetControlFocus' method.
  116.     // It specifies whether focus should be set to the next or previous
  117.     // sibling of the current control with focus.
  118.     //
  119.     enum THow {
  120.       Next,         // Set focus to the next sibling
  121.       Previous      // Set focus to the previous sibling
  122.     };
  123.     void            SetControlFocus(HWND hwnd);
  124.     void            SetControlFocus(THow how);
  125.  
  126.     void            SetMsgResult(uint32 result);
  127.  
  128.     // Message response functions
  129.     //
  130.     void            EvClose();
  131.     void            EvPaint();
  132.     HBRUSH          EvCtlColor(HDC, HWND hWndChild, uint ctlType);
  133.     uint32          EvGetDefId();
  134.     bool            EvSetDefId(int id);
  135. #if defined(BI_PLAT_WIN32)
  136.     void            EvReposition();
  137. #endif
  138.  
  139.     // Child notifications
  140.     //
  141.     void            CmOk();      // IDOK
  142.     void            CmCancel();  // IDCANCEL
  143.  
  144. #if defined(OWL2_COMPAT)
  145.     // Returns the handle of the dialog's control with the passed Id
  146.     // Obsolete- use TWindow::GetDlgItem(Id)
  147.     //
  148.     HWND            GetItemHandle(int childId);
  149. #endif
  150.  
  151.     // Sends the passed message to the dialog's control which has id DlgItemId
  152.     // Obsolete- use TWindow::SendDlgItemMessage()
  153.     //
  154.     uint32 SendDlgItemMsg(int childId, uint16 msg, uint16 wParam, uint32 lParam);
  155.  
  156.     // Callback procs for hooking TDialog to native window
  157.     //
  158.     static int CALLBACK StdDlgProc(THandle, uint, TParam1, TParam2);
  159.  
  160.     // Handle enabling and disabling of child controls
  161.     //
  162.     bool            IdleAction(long idleCount);
  163.  
  164.   protected:
  165.     // Override virtual functions defined by class TWindow
  166.     //
  167.     void            SetupWindow();
  168.     char far*       GetClassName();
  169.     void            GetWindowClass(WNDCLASS& wndClass);
  170.  
  171.     // Registers WINDOW class(es) of Children
  172.     //
  173.     void            RegisterChildObjects();
  174.  
  175.   public_data:
  176.     union {
  177.       TDialogAttr  Attr;        // Old name
  178.       TDialogAttr  DialogAttr;  // New name
  179.     };
  180.     bool         IsModal;
  181.  
  182.   private:
  183.     // Hidden to prevent accidental copying or assignment
  184.     //
  185.     TDialog(const TDialog&);
  186.     TDialog& operator =(const TDialog&);
  187.  
  188.   DECLARE_RESPONSE_TABLE(TDialog);
  189.   DECLARE_STREAMABLE(_OWLCLASS, TDialog, 1);
  190. };
  191.  
  192. // Generic definitions/compiler options (eg. alignment) following the
  193. // definition of classes
  194. #include <services/posclass.h>
  195.  
  196. #if defined(BI_NAMESPACE)
  197. } // namespace OWL
  198. #endif
  199.  
  200. //----------------------------------------------------------------------------
  201. // Inline implementations
  202. //
  203.  
  204. //
  205. inline uint32
  206. TDialog::SendDlgItemMsg(int ChildId, uint16 Msg, uint16 WParam, uint32 LParam) {
  207.   return SendDlgItemMessage(ChildId, Msg, WParam, LParam);
  208. }
  209.  
  210. //
  211. // Set the result of the message for the dialog's WndProc.
  212. //
  213. inline void
  214. TDialog::SetMsgResult(uint32 result)
  215. {
  216.   PRECONDITION(GetHandle());
  217.   SetWindowLong(DWL_MSGRESULT, result);
  218. }
  219.  
  220. //
  221. // Return the ID of the default pushbutton.
  222. //
  223. inline uint
  224. TDialog::GetDefaultId() const
  225. {
  226.   PRECONDITION(GetHandle());
  227.   return LoUint16(CONST_CAST(TDialog*,this)->SendMessage(DM_GETDEFID));
  228. }
  229.  
  230. //
  231. // Return the attributes data member of TDialog.
  232. //
  233. inline TDialogAttr&
  234. TDialog::GetDialogAttr()
  235. {
  236.   return Attr;
  237. }
  238.  
  239. //
  240. // Set the attributes of the dialog.
  241. //
  242. inline void
  243. TDialog::SetDialogAttr(TDialogAttr attr)
  244. {
  245.   Attr = attr;
  246. }
  247.  
  248. //
  249. // Return true if the dialog is modal.
  250. //
  251. inline bool
  252. TDialog::GetIsModal() const
  253. {
  254.   return IsModal;
  255. }
  256.  
  257. //
  258. // Set the modal data member of TDialog.
  259. //
  260. inline void
  261. TDialog::SetIsModal(bool ismodal)
  262. {
  263.   IsModal = ismodal;
  264. }
  265.  
  266. //
  267. // Set the id of the default push button.
  268. //
  269. inline void
  270. TDialog::SetDefaultId(uint id)
  271. {
  272.   PRECONDITION(GetHandle());
  273.   SendMessage(DM_SETDEFID, id, 0);
  274. }
  275.  
  276. //
  277. // Convert the dialog units into screen coordinates.
  278. //
  279. inline void
  280. TDialog::MapDialogRect(TRect& rect)
  281. {
  282.   PRECONDITION(GetHandle());
  283.   ::MapDialogRect(GetHandle(), &rect);
  284. }
  285.  
  286. #if defined(OWL2_COMPAT)
  287. //
  288. inline HWND
  289. TDialog::GetItemHandle(int childId)
  290. {
  291.   PRECONDITION(GetHandle());
  292.   return GetDlgItem(childId);
  293. }
  294. #endif
  295.  
  296. #if defined(BI_PLAT_WIN32)
  297. //
  298. // Reposition the dialog to ensure it is fully visible.
  299. //
  300. inline void
  301. TDialog::Reposition()
  302. {
  303.   PRECONDITION(GetHandle());
  304.   SendMessage(DM_REPOSITION);
  305. }
  306. #endif
  307.  
  308. #endif  // OWL_DIALOG_H
  309.